package com.rdExpenses.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.base.common.persistence.Page;
import com.base.common.service.CrudService;
import com.base.common.utils.SQLUtil;
import com.company.model.CompanyProject;
import com.rdExpenses.dao.ExpenseInfoMapper;
import com.rdExpenses.model.ExpenseInfo;
import com.rdExpenses.service.ExpenseService;

@Service
public class ExpenseServiceImpl extends CrudService<ExpenseInfoMapper, ExpenseInfo> implements ExpenseService {

	public List<ExpenseInfo> findExpenseListByCompanyId(String companyId) throws Exception {
		Map<String, String> params = new HashMap<String, String>();
		params.put("companyId", companyId);
		String sql = "SELECT i.id,i.expense_type_id,i.expense,i.billing_date,i.project_id,i.company_id,i.memo,"
				+ "t.expense_name as expense_type_name,p.project_name FROM company_project  p ,expense_info  i ,expense_type  t "
				+ "WHERE p.id =  i.project_id AND i.expense_type_id =  t.id and i.company_id =  #{companyId} ";
		List<ExpenseInfo> list = this.getList(sql, ExpenseInfo.class, params);
		return list;
	}

	public boolean saveExpense(ExpenseInfo expenseInfo) throws Exception {
		int res = this.saveOrUpdate(expenseInfo);
		return true;
	}

	public boolean deleteExpenseByIds(String ids) throws Exception {
		String sql = "delete from expense_info where id in (" + SQLUtil.createInStr(ids) + ") ";
		int res = this.delete(sql);
		return true;
	}

}
